#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <set>
#include <queue>

using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int N = 110;

int n;
int num[N];
bool st[N];
vector<int> res;



void dfs(int u, bool flag){

    if(u == n){
        for(int i = 0; i < n; i ++) cout << res[i] << " ";
        exit(0);
    }

    int r;
    if(flag){
        r = n;
    }else{
        r = (u == n - 1) ? num[u] - 1: num[u];
    }
  //  cout << "u: " << u << " r: " << r << '\n';
    for(int i = r; i >= 1; i --){
        if(!st[i]){
            st[i] = true;
            res.push_back(i);

            if(i == num[u]) dfs(u + 1, false);
            else dfs(u + 1, true);

            st[i] = false;
            res.pop_back();
        }
    }
}


int main(){
#ifdef LOCALFLAG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif


    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;
    for(int i = 0; i < n; i ++) cin >> num[i];

    dfs(0, false);

    return 0;
}